home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGASIC
/
SAYGET.LZH
/
SYGTDEMO.BAS
< prev
next >
Wrap
BASIC Source File
|
1987-06-15
|
13KB
|
245 lines
' QBSAYGET.BAS: a Quick Basic subroutine version 1
' adapted by : Lee M. Bernbaum from the original SAYGET.BAS written for
' : Turbo Basic;also added TRIM subprogram at end
' : of listing.
' author .....: Vernon E. Davis [71330,2705]
' purpose ....: emulates the dBASE @..SAY..GET..READ statement that
' : allows bullet-proof string input from the keyboard.
' syntax .....: Call SAYGET( row, colunm, saystring, getstring ) where
' : row = 1 to 25
' : colunm = 1 to 80
' : saystring = string to SAY on the screen
' : getstring = string to GET on the screen
' : NOTE: the entire SAYGET combination MUST fit on one line
' returns ....: the data in getstring
' notes ......: there are four shared variables that MUST be declared.
' : S.FORE% - the text color of the normal screen.
' : S.BACK% - the background color of the normal screen.
' : G.FORE% - the text color of the GET input line.
' : G.BACK% - the background color of the GET input line.
' : the following editing keys are operational:
' : RETURN - returns to calling routine with changes
' : ESC - returns to calling routine without changes
' : Left Arrow - moves one character left, non-destructive
' : Right Arrow - moves one character right, non-destructive
' : HOME - moves to beginning of GET line
' : END - moves to end of GET line
' : Backspace - moves one character left, destructive. If this
' : key is used on the last character of the GET
' : line, it will not erase it. Use the DEL key.
' : DEL - deletes character from cursor position
' : INS - toggles insert on and off. INS indicator appears
' : at row 1, column 60 when insert is on
'
' Turbo Basic is a product from Borland International
' Quick Basic is a product from Microsoft Corporation
' dBASE is a registered trademark of Ashton-Tate
'
' start delete here to remove demo...................................
'
' *** MAIN PROGRAM ***
'
' the main program is only a demo for the SAYGET subroutine. It is not
' required to use the SAYGET subroutine. clip it out with your editor before
' $INCLUDING this file in your programs.
'
S.FORE% = 7 ' color of normal text
S.BACK% = 0 ' color of normal background
G.FORE% = 0 ' color of GET text
G.BACK% = 7 ' color of GET background
Cls
Locate 3,1
Print "Test Program for SAYGET procedure. Written by Vernon E. Davis"
Print "TRIM written, and SAYGET adapted for Quick Basic by Lee M. Bernbaum"
Locate 10,1
Print "RETURN - returns to calling routine with changes"
Print "ESC - returns to calling routine without changes"
Print "Left Arrow - moves one character left, non-destructive"
Print "Right Arrow - moves one character right, non-destructive"
Print "HOME - moves to beginning of GET line"
Print "END - moves to end of GET line"
Print "Backspace - moves one character left, destructive. If this"
Print " key is used on the last character of the GET"
Print " line, it will not erase it. Use the DEL key."
Print "DEL - deletes character from cursor position"
Print "INS - toggles insert on and off. INS indicator appears"
Print " at row 1, column 60 when insert is on"
saygetstr$ = "The SAYED string sent to SAYGET" ' initialize GET string
first.len%=int(len(saygetstr$))
Do
Call SAYGET(6,1,"Enter any data or Q to quit-> ",saygetstr$,7,0,0,7)
trim$=saygetstr$:tlen%=0
Call TRIM(trim$,tlen%)
locate 7,1:print "The returned string SAYGET = ";Chr$(34);saygetstr$;Chr$(34)
locate 8,1:print "The returned string TRIMMED = "+Chr$(34)+trim$+Chr$(34)+_
string$(len(saygetstr$)-tlen%,32)
if tlen%<>0 then
saygetstr$=left$(trim$+string$(first.len%," "),first.len%)
else
saygetstr$=string$(first.len%,42)
end if
Loop Until tlen%=1 and trim$="q" OR trim$="Q"
Cls
End
'
'stop deleting here when removing demo...............................
Sub SAYGET(ypos%,xpos%,saystr$,getstr$,S.FORE%,S.BACK%,G.FORE%,G.BACK%) static
' Shared G.FORE%,G.BACK%,S.FORE%,S.BACK%
inskey%=0 ' insert key initially off
gstrlen%=Len(getstr$) ' get GET string length
Locate ypos%,xpos%,1 : Print saystr$; ' print SAY string
getbegin%=Pos(0) ' store beginning screen pos
getend%=(getbegin%+gstrlen%)-1 ' store end screen pos
If getend% > 80 Then getend%=80 ' insure string fits on line
Color G.FORE%,G.BACK% ' change to GET colors
Locate ypos%,getbegin%,1 : Print getstr$; ' print GET string
Locate ypos%,getbegin% ' return cursor to beginning
Do '
Do '
ch$=Inkey$ ' get character from kbd
Loop Until ch$ <> "" '
' check for these keys ...
IF ch$=Chr$(13) then ' ** RETURN Key **
getstr$="" ' clear GET string
For i%=getbegin% To getend% '
h%=Screen(ypos%,i%) ' get char. from screen
getstr$=getstr$+Chr$(h%) ' and place it in GET string
Next i% '
Color S.FORE%,S.BACK% ' change normal color
Exit Sub ' and return to caller
ELSEIF ch$=Chr$(0)+Chr$(75) then ' ** Left Arrow Key **
If Pos(0)=getbegin% Then ' if at the begin of line
Locate ypos%,getbegin% ' remain there
Else ' else
Locate ypos%,Pos(0)-1 ' move 1 char. left
End If '
ELSEIF ch$=Chr$(0)+Chr$(77) then ' ** Right Arrow Key **
Locate ypos%,Pos(0)+1 ' move 1 char. right
If Pos(0)>=getend% Then ' if at the end of line
Locate ypos%,getend% ' remain there
End If '
ELSEIF ch$=Chr$(0)+Chr$(71) then ' ** Home Key **
Locate ypos%,getbegin% ' move to begin of line
ELSEIF ch$=Chr$(0)+Chr$(79) then ' ** End Key **
Locate ypos%,getend% ' move to end of line
ELSEIF ch$=Chr$(0)+Chr$(83) then ' ** Del Key **
j%=Pos(0) ' store current horiz.
t0$="" ' clear temp string
For i%=getbegin% To getend% '
h%=Screen(ypos%,i%) ' get char. from screen
If Pos(0)<>i% Then ' if not equal to horiz.
t0$=t0$+Chr$(h%) ' place it in temp string
End If '
Next i% '
t0$=t0$+" " ' place blank at end
Locate ypos%,getbegin% : Print t0$; ' replace string on screen
Locate ypos%,j% ' and return to horiz.
ELSEIF ch$=Chr$(0)+Chr$(82) then ' ** Ins Key **
If inskey%=0 Then ' if ins toggle off
inskey%=1 ' turn ins toggle on
j%=Pos(0) ' store current horiz.
Color S.FORE%,S.BACK% ' normal colors
Locate 1,60,0 : Print "INS" ' say that INS is on
Locate ypos%,j%,1 ' return to horiz.
Color G.FORE%,G.BACK% ' and GET colors
Else ' if ins toggle on
inskey%=0 ' turn ins toggle off
j%=Pos(0) ' save current horiz.
Color S.FORE%,S.BACK% ' normal colors
Locate 1,60,0 : Print " " ' say that INS is off
Locate ypos%,j%,1 ' return to horiz.
Color G.FORE%,G.BACK% ' and GET colors
End If '
ELSEIF ch$=Chr$(8) then ' ** Backspace Key **
If Pos(0)<>getbegin% Then ' if not at begin of line
Locate ypos%,Pos(0)-1 ' move back one space
Print " "; ' print a space
Locate ypos%,Pos(0)-1 ' and move back again
End If '
ELSEIF ch$=Chr$(27) then ' ** Escape Key **
Color S.FORE%,S.BACK% ' normal color
Exit Sub ' return w/o modification
ELSE
IF asc(ch$)>=32 and asc(ch$)<=126 then ' ** Alphanumeric Keys **
If inskey%=1 Then ' if ins toggle on
j%=Pos(0) ' store current horiz.
t0$="" ' clear temp string
For i%=getbegin% To getend%-1 '
h%=Screen(ypos%,i%) ' get char. from screen
If Pos(0)=i% Then ' if horiz.
t0$=t0$+ch$ ' add char. in temp string
End If '
t0$=t0$+Chr$(h%) ' add screen chars.
Next i% '
if j%=getend% then t0$=left$(t0$,getend%-1)+ch$
Locate ypos%,getbegin% : Print t0$; ' replace string on screen
if j%=getend% then ' and return to horiz.
locate ypos%,j%
else
locate ypos%,j%+1
end if
Else ' if ins toggle off
Print ch$; ' print char.
If Pos(0)>getend% Then ' if at end of line
Locate ypos%,getend% ' remain at end of line
End If '
End If '
ELSE
Locate ypos%,getend% ' remain there
END IF '
END IF
Loop Until TRUE ' loop always
End Sub ' >>> End of SAYGET <<<
'
' TRIM : a Quick Basic subprogram version 1
' author .....: Lee M. Bernbaum
' purpose ....: removes trailing blanks from a character string
' syntax .....: Call TRIM( trim$, tlen%) where
' : trim$ = the string to be trimmed
' : tlen% = the length of the returned string
' returns ....: the string minus trailing blanks
sub TRIM(trim$,tlen%) static
length%=len(trim$)
if length%=0 or trim$=string$(length%," ") then
trim$=""
tlen%=0
exit sub
end if
while length% > 0
chk$ = mid$(trim$,length%,1) 'start at end of string
if chk$ = chr$(0) or chk$=chr$(255) or chk$=" " then
length% = length%-1 'blank - keep checking
else
trim$ = left$(trim$,length%) 'terminate at first
tlen% = length% 'non-blank character
exit sub
end if
wend
end sub